package com.sbr.seb.wicket.entity;

import java.util.List;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.basic.MultiLineLabel;
import org.apache.wicket.model.AbstractReadOnlyModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sbr.seb.entity.Log;

public class LogLabel extends MultiLineLabel {

	public LogLabel(String id, String log) {
		super(id, new LogModel(log));
	}

	public LogLabel(String id, List<Log> logList) {
		super(id, new LogModel(logList));
	}


	private static class LogModel extends AbstractReadOnlyModel<String> {

		private static final Logger logger = LoggerFactory.getLogger(LogModel.class);

		private StringBuilder sb;
		private List<Log> logList;

		/**
		 * @param tz
		 */
		public LogModel(String log) {
		}

		public LogModel(List<Log> logList) {
			sb = new StringBuilder();
			this.logList = logList;
		}

		/**
		 * @see org.apache.wicket.model.AbstractReadOnlyModel#getObject()
		 */
		@Override
		public String getObject() {
			logger.debug("{}",logList.size());
			sb.append(logList.get(logList.size()-1).getCompleteLog());
			return sb.toString();
		}
	}
}
